package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Name   string `gorm:"type:varchar(20);not null"`
	Email  string `gorm:"type:varchar(20);not null"`
	Status int    `gorm:"int(1);not null;comment:1-正常 2-异常"`
}

type Goods struct {
	gorm.Model
	Name  string  `gorm:"type:varchar(20);not null"`
	Price float64 `gorm:"type:decimal(10,2);not null"`
	Stock int     `gorm:"type:int(5);not null"`
}
type Order struct {
	gorm.Model
	UserId  int     `gorm:"type:tinyint;not null"`
	GoodsId int     `gorm:"type:tinyint;not null"`
	Num     int     `gorm:"type:int(5);not null"`
	OrderSn string  `gorm:"type:varchar(36);not null"`
	Status  string  `gorm:"type:varchar(20);not null;comment:已支付 未支付 已取消"`
	PayType string  `gorm:"type:varchar(20);not null;comment:支付宝 微信"`
	Amount  float64 `gorm:"type:decimal(10,2);not null;comment:总价"`
}

func (g *Goods) Add() error {
	return DB.Create(&g).Error
}
func (g *Goods) GetGoodsInfo(goodsId int) error {
	return DB.Where("id = ?", goodsId).First(&g).Error
}
func (o *Order) Add() error {
	return DB.Create(&o).Error
}
